<template>
	<view class="content" v-if="show==1">
		<view class="main">
			<view class="zhanghu" @click="kai">
				<image class="zhanghu2" src="../../static/images/zfb.png" mode="aspectFill"></image>
				<view class="zhanghu3" v-if="money.no">
					<view class="zhanghu3-1">{{money.name}}</view>
					<view class="zhanghu3-2">{{money.no}}</view>
				</view>
				<view class="zhanghu3" v-if="!money.no">
					请先设置收款支付宝
				</view>
				<image class="zhanghu4" src="../../static/images/right_2.png" mode="aspectFill"></image>
			</view>
			<view class="tixian">
				<view class="tixian2">
					<text class="tixian2-1">提现金额</text>
					<text class="tixian2-2" @click="quanbu">全部提现</text>
				</view>
				<view class="tixian3">
					<text>￥</text>
					<input type="digit" @input="jine" :value="money.money" placeholder-style="font-size:0.9rem;" placeholder="请输入提现金额"/>
				</view>
			</view>
			<view class="info" style="border: 0px;line-height: 22px;color:#666;">
				当前可提现{{user.money}}元
			</view>
			<view class="info" style="border: 0px;line-height: 22px;margin-top: 8px;color:red;">
				提示：
			</view>
			<view class="info" style="border: 0px;line-height: 18px;margin-top: 8px;color:red;">
				1、最低提现金额为{{site.dl_tx_min}}元<text v-if="site.dl_tx_bl>0">，提现需支付{{site.dl_tx_bl}}%服务费</text>
			</view>
			<view class="info" style="border: 0px;line-height: 18px;margin-top: 8px;color:red;">
				2、一天最多只能提现一次，提现后1-7天内到账
			</view>
			<view class="info4" @click="baocun">
				立即提现
			</view>
		</view>
		
		<view class="zheceng" v-if="is_t==true"></view>
		<view class="tianjia" v-if="is_t==true">
			<view class="tianjia2">
				<text>设置支付宝</text>
				<image @click="kai" src="../../static/cha.png" mode="aspectFill"></image>
			</view>
			<view class="tianjia3">
				<input type="text" @input="zhanghu" :value="money.no" placeholder="请填写您的支付宝账号"/>
			</view>
			<view class="tianjia3">
				<input type="text" @input="name2" :value="money.name" placeholder="请填写支付宝账号认证姓名"/>
			</view>
			<view class="tianjia4" @click="queren">确定</view>
		</view>
	</view>
</template>

<script>
	var app=getApp();
	export default {
		data() {
			return {
				show:0,
				uid:0,
				money:{money:'',name:'',no:''},
				user:[],
				is_t:false,
				alipay:'',
				name:'',
				site:[]
			}
		},
		onLoad() {
			const uid = uni.getStorageSync('uid');
			if(app.isBlank(uid)==true){
				app.error_msg("请先登录");
			}
			this.uid=uid;
			this.getdata();
		},
		methods: {
			getdata(){
				var that=this;
				uni.showLoading({
				    title: '数据加载中'
				});
				uni.request({
				    url: app.globalData.url+"user/tixian",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							app.error_msg(res.data.msg);
						}
						that.user=res.data.data.user
						that.site=res.data.data.site
						that.money.name=res.data.data.user.name;
						that.money.no=res.data.data.user.alipay;
						that.name=res.data.data.user.name;
						that.alipay=res.data.data.user.alipay;
						that.show=1;
				    }
				});
			},
			quanbu(){
				if(this.user.money<=0){
					return false;
				}
				this.money.money=this.user.money;
			},
			kai(){
				this.is_t=!this.is_t;
			},
			baocun(){
				var that=this;
				if(app.isBlank(this.money.money)==true){
					uni.showToast({
					    title: "请输入提现金额",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				var m=/^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
				if(!m.test(this.money.money)){
					uni.showToast({
					    title: "提现金额必须为大于0的数字",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(this.money.money>this.user.money){
					uni.showToast({
					    title: "可提现余额不足",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(app.isBlank(this.money.no)==true){
					uni.showToast({
					    title: "请先设置收款支付宝账户",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(app.isBlank(this.money.name)==true){
					uni.showToast({
					    title: "请先设置收款支付宝账户",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				uni.showModal({
				    title: '确认提现到支付宝账户',
				    content: that.money.name+' '+that.money.no,
				    success: function (res2) {
				        if (res2.confirm) {
				            uni.showLoading({
				                title: '请求中'
				            });
				            var u=JSON.stringify(that.money);
				            u=JSON.parse(u)
				            u.uid=that.uid;
				            uni.request({
				                url: app.globalData.url+"user/submitWithdraw",
				            	method:"POST",
				            	dataType:"json",
				            	header: {
				            	    'content-type': 'application/x-www-form-urlencoded'
				            	},
				                data: u,
				                success: (res) => {
				            		uni.hideLoading();
				            		if(res.data.code!=1){
				            			uni.showToast({
				            			    title: res.data.msg,
				            				icon:'none',
				            			    duration: 1500
				            			});
				            			return false;
				            		}
				            		uni.showModal({
				            		    content: res.data.msg,
				            			showCancel:false,
				            			confirmText:'好的',
				            		    success: function (res) {
				            		        if (res.confirm) {
				            		            uni.navigateBack({
				            		                delta: 1
				            		            });
				            		        }
				            		    }
				            		});
				                }
				            });
				        }
				    }
				});
				
			},
			queren(){
				if(app.isBlank(this.alipay)==true){
					uni.showToast({
					    title: "请输入支付宝账号",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(app.isBlank(this.name)==true){
					uni.showToast({
					    title: "请输入支付宝账号认证姓名",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				this.money.name=this.name;
				this.money.no=this.alipay;
				this.is_t=false;
			},
			jine: function(event) {
			    this.money.money = event.target.value
			},
			zhanghu: function(event) {
			    this.alipay = event.target.value
			},
			name2: function(event) {
			    this.name = event.target.value
			}
		}
	}
</script>

<style>
	.tianjia4{width:94%;margin: 0 auto;height:35px;text-align: center;line-height: 35px;background-color: #05c160;color:#fff;border-radius: 5px;}
	.tianjia3 input{height:40px;font-size: 0.85rem;}
	.tianjia3{border:1px #eee solid;height:40px;width:90%;margin: 0px auto;padding: 0px 2%;border-radius: 5px;margin-bottom: 15px;}
	.tianjia2 image{width:20px;height:20px;float: right;margin-top: 12.5px;}
	.tianjia2 text{font-weight: 550;}
	.tianjia2{width:94%;padding: 0px 3%;height:45px;line-height: 45px;}
	.tianjia{width:100%;height:200px;background-color: #fff;position: fixed;bottom: 0px;z-index: 9999;border-top-left-radius: 5px;border-top-right-radius: 5px;}
	.zheceng{width:100%;height:100vh;background-color: #000000;opacity: 0.6;z-index: 9998;position: fixed;top:0px;}
	.tixian3 input{height:50px;font-size: 1.4rem;}
	.tixian3 text{font-size: 1.8rem;float: left;margin-right: 5px;}
	.tixian3{width:100%;height:50px;line-height: 50px;border-bottom: 1px rgb(245, 245, 245) solid;}
	.tixian2-2{color:#05c160;float: right;}
	.tixian2-1{font-size: 0.95rem;font-weight: 550;}
	.tixian2{width:100%;height:40px;line-height: 40px;}
	.tixian{width:94%;padding: 5px 3%;}
	.zhanghu3-2{width:100%;height:25px;line-height: 20px;overflow: hidden;font-size: 0.8rem;color:#666;}
	.zhanghu3-1{width:100%;height:25px;line-height: 30px;overflow: hidden;}
	.zhanghu4{width:20px;height:20px;margin-top: 15px;}
	.zhanghu3{width:100%;height:50px;line-height: 50px;flex: 1;}
	.zhanghu2{width:30px;height:30px;margin-top: 10px;margin-right: 8px;}
	.zhanghu{width:94%;padding: 10px 3%;display: flex;border-bottom: 10px rgb(245, 245, 245) solid;}
	.fei text{color:red;}
	.fei{width:100%;height:25px;line-height: 25px;font-size: 0.75rem;text-align: right;}
	.info3 text{float: right;color:red;line-height: 45px;}
	.info3-1{width:100%;height:45px;line-height: 45px;text-align: right;}
	.info4{width:94%;margin:0px 3%;height:45px;line-height: 45px;text-align: center;background-color: #05c160;border-radius: 5px;margin-top: 50px;color:#fff;}
	.info3 image{width:45px;height:45px;margin-top: 7.5px;float: right;}
	.info3 input{width:100%;height:45px;font-size: 0.85rem;color:#333;}
	.info3{width:100%;height:45px;flex:1;}
	.info2{width:100px;height:45px;line-height: 45px;margin-right: 5px;color:#333;font-weight: 550;}
	.info{width:90%;padding: 0px 5%;display: flex;border-bottom: 1px rgb(245, 245, 245) solid;}
	.main{width:100%;}
</style>
